# coding=utf-8
from protobuf_base.common_pb2 import *  # @UnusedWildImport
import protobuf_to_dict as ptd
from google.protobuf.descriptor import FieldDescriptor
import json
from protobuf_to_dict.convertor import TYPE_CALLABLE_MAP, EXTENSION_CONTAINER,\
    _get_field_value_adaptor, repeated

class UFOFileDict(object):
    '''
    # 区分UFOFile, 用于在记录日志时过滤文件内容
    '''
   
    def __init__(self):
        self.kk = {} 
    
    def __getitem__(self, key):  
        return self.kk[key];
      
    def __setitem__(self, key, value):  
        self.kk[key] = value
        
    def new_dict(self):
        return self.kk.copy()
    
    def to_dict(self):
        return self.kk

class LogEncoder(json.JSONEncoder):
    '''
    encoder for logging
    '''
    
    def default(self, obj):
        if isinstance(obj, UFOFileDict):
            obj = obj.new_dict()
            if obj['content']:
                obj['content'] = 'file'
            return obj
        else:
            return json.JSONEncoder.default(self, obj)



